// 2025/07/26
// Author: Forever
#include <bits/stdc++.h>
using namespace std;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& vec)
{
    os << "["; 
    bool first = true;
    for (const auto& item : vec) {
        if (!first)
            os << ", "; 
        os << item;
        first = false;
    }
    os << "]"; 
    return os;
}
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& p)
{
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename A, typename B>
ostream& operator<<(ostream& os, const map<A, B>& m)
{
    os << "{";
    bool first = true;
    for (const auto& p : m) {
        if (!first)
            os << ", ";
        os << p.first << ": " << p.second;
        first = false;
    }
    os << "}";
    return os;
}
template <typename A, typename B>
ostream& operator<<(ostream& os, const unordered_map<A, B>& m)
{
    os << "{";
    bool first = true;
    for (const auto& p : m) {
        if (!first)
            os << ", ";
        os << p.first << ": " << p.second;
        first = false;
    }
    os << "}";
    return os;
}
#define error(args...)                           \
    {                                            \
        string _s = #args;                       \
        replace(_s.begin(), _s.end(), ',', ' '); \
        stringstream _ss(_s);                    \
        istream_iterator<string> _it(_ss);       \
        cout << "-----DEBUG-----" << endl;     \
        err(_it, args);                          \
        cout << "------END------" << endl;     \
    }
void err(istream_iterator<string> it) { }
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
    cout << *it << " = " << a << endl;
        err(++it, args...);
}
void setIO(string name = "")
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if (!name.empty()) {
        freopen((name + ".in").c_str(), "r", stdin);
        freopen((name + ".out").c_str(), "w", stdout);
    }
}
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const ll INFLL = 0x3f3f3f3f3f3f3f3fLL;
ll quick_pow(ll base, ll exp, ll mod = MOD)
{
    ll res = 1;
    while (exp) {
        if (exp & 1) {
            res = res * base % mod;
        }
        base = base * base % mod;
        exp >>= 1;
    }
    return res;
}
ll gcd(ll a, ll b)
{
    return b == 0 ? a : gcd(b, a % b);
}

const int MAXN = 200001;
int n, m, a[MAXN], mx[MAXN], mi[MAXN];

void build(int rt, int l, int r){
    if (l == r) {
        mx[rt] = mi[rt] = a[l];
        return;
    }
    int mid = (l + r) >> 1;
    build(rt << 1, l, mid);
    build(rt << 1 | 1, mid + 1, r);
    mx[rt] = max(mx[rt << 1], mx[rt << 1 | 1]);
    mi[rt] = min(mi[rt << 1], mi[rt << 1 | 1]);
}

int query_max(int rt, int l, int r, int ql, int qr){
    if (ql <= l && r <= qr) {
        return mx[rt];
    }
    int mid = (l + r) >> 1, ans = -INF;
    if (ql <= mid) 
        ans = max(ans, query_max(rt << 1, l, mid, ql, qr));
    if (qr > mid) 
        ans = max(ans, query_max(rt << 1 | 1, mid + 1, r, ql, qr));
    return ans;
}

int query_min(int rt, int l, int r, int ql, int qr){
    if (ql <= l && r <= qr) {
        return mi[rt];
    }
    int mid = (l + r) >> 1, ans = INF;
    if (ql <= mid) 
        ans = min(ans, query_min(rt << 1, l, mid, ql, qr));
    if (qr > mid) 
        ans = min(ans, query_min(rt << 1 | 1, mid + 1, r, ql, qr));
    return ans;
}

signed main()
{
    setIO();
    cin >> n >> m;
    for (int i = 1; i <= n; i++) 
        cin >> a[i];
    build(1, 1, n);
    for (int i = 1; i <= m; i++) {
        int l, r;
        cin >> l >> r;
        cout << query_max(1, 1, n, l, r) - query_min(1, 1, n, l, r) << endl;
    }
    return 0;
}